/*
 * Created by JFormDesigner on Sat Mar 03 12:03:48 GMT 2007
 */

package mv.releaser.view;

import java.awt.*;
import java.awt.event.*;
import java.util.*;
import javax.swing.*;
import mv.releaser.controler.ControlerMvReleaser;
import mv.releaser.model.MvReleaser;

/**
 * @author kal kal
 */
public class MainWindowJFormD extends JFrame implements InterfaceMainWindow {

	private GregorianCalendar			cal;
	private final ControlerMvReleaser	controler;
	private MvReleaser					mvReleaser;
	private String						releaseName;
	private MainJPanel					mainPanel;

	public MainWindowJFormD(ControlerMvReleaser controler, MvReleaser mvReleaser) {
		super("MvReleaser");
		this.controler = controler;
		this.mvReleaser = mvReleaser;
		mainPanel = new MainJPanel(controler, mvReleaser);

		initComponents();
		updateLookAndFeelMenu(lookfeelMenu);
		getContentPane().add(mainPanel, BorderLayout.CENTER);
		pack();
	}

	private void browseButtonActionPerformed(ActionEvent e) {
		controler.openAviFile();
	}

	private void aboutMenuItemActionPerformed(ActionEvent e) {
		controler.about();
	}

	private void thisWindowClosing(WindowEvent e) {
		controler.saveConfiguration();
	}

	private void menuItem2ActionPerformed(ActionEvent e) {
		controler.saveConfiguration();
	}

	private void initComponents() {
		// JFormDesigner - Component initialization - DO NOT MODIFY
		// //GEN-BEGIN:initComponents
		// Generated using JFormDesigner Evaluation license - kal kal
		ResourceBundle bundle = ResourceBundle
				.getBundle("mv.releaser.view.properties");
		menuBar1 = new JMenuBar();
		menu1 = new JMenu();
		menuItem1 = new JMenuItem();
		menuItem2 = new JMenuItem();
		lookfeelMenu = new JMenu();
		helpMenu = new JMenu();
		aboutMenuItem = new JMenuItem();

		// ======== this ========
		setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
		setIconImage(new ImageIcon(getClass().getResource(
				"/mv/releaser/resources/mediaplayer-0.png")).getImage());
		addWindowListener(new WindowAdapter() {
			@Override
			public void windowClosing(WindowEvent e) {
				thisWindowClosing(e);
			}
		});
		Container contentPane = getContentPane();
		contentPane.setLayout(new BorderLayout());

		// ======== menuBar1 ========
		{

			// ======== menu1 ========
			{
				menu1.setText(bundle.getString("MainWindowJFormD.menu1.text"));

				// ---- menuItem1 ----
				menuItem1.setText(bundle
						.getString("MainWindowJFormD.menuItem1.text"));
				menuItem1.addActionListener(new ActionListener() {
					public void actionPerformed(ActionEvent e) {
						browseButtonActionPerformed(e);
					}
				});
				menu1.add(menuItem1);
				menu1.addSeparator();

				// ---- menuItem2 ----
				menuItem2.setText(bundle
						.getString("MainWindowJFormD.menuItem2.text"));
				menuItem2.addActionListener(new ActionListener() {
					public void actionPerformed(ActionEvent e) {
						menuItem2ActionPerformed(e);
					}
				});
				menu1.add(menuItem2);
			}
			menuBar1.add(menu1);

			// ======== lookfeelMenu ========
			{
				lookfeelMenu.setText(bundle
						.getString("MainWindowJFormD.lookfeelMenu.text"));
			}
			menuBar1.add(lookfeelMenu);

			// ======== helpMenu ========
			{
				helpMenu.setText(bundle
						.getString("MainWindowJFormD.helpMenu.text"));

				// ---- aboutMenuItem ----
				aboutMenuItem.setText(bundle
						.getString("MainWindowJFormD.aboutMenuItem.text"));
				aboutMenuItem.addActionListener(new ActionListener() {
					public void actionPerformed(ActionEvent e) {
						aboutMenuItemActionPerformed(e);
					}
				});
				helpMenu.add(aboutMenuItem);
			}
			menuBar1.add(helpMenu);
		}
		setJMenuBar(menuBar1);
		pack();
		setLocationRelativeTo(getOwner());
		// //GEN-END:initComponents
	}

	// JFormDesigner - Variables declaration - DO NOT MODIFY
	// //GEN-BEGIN:variables
	// Generated using JFormDesigner Evaluation license - kal kal
	private JMenuBar	menuBar1;
	private JMenu		menu1;
	private JMenuItem	menuItem1;
	private JMenuItem	menuItem2;
	private JMenu		lookfeelMenu;
	private JMenu		helpMenu;
	private JMenuItem	aboutMenuItem;

	// JFormDesigner - End of variables declaration //GEN-END:variables

	protected void generate() {
		controler.generate();

	}

	protected void browse() {
		controler.openAviFile();
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see mv.releaser.view.InterfaceMainWindow#getLookAndFeelsMap()
	 */
	public Map<String, String> getLookAndFeelsMap() {
		UIManager.LookAndFeelInfo[] info = UIManager.getInstalledLookAndFeels();
		Map<String, String> map = new TreeMap<String, String>();
		for (int i = 0; i < info.length; i++) {
			String nomLF = info[i].getName();
			String nomClasse = info[i].getClassName();
			map.put(nomLF, nomClasse);
		}
		return map;
	}

	public String getTitleSong() {
		return mainPanel.getTitleSong();
	}

	public String getArtist() {
		return mainPanel.getArtist();
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see mv.releaser.view.InterfaceMainWindow#getRelease()
	 */
	public String getRelease() {
		return mainPanel.getRelease();
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see mv.releaser.view.InterfaceMainWindow#getCrc()
	 */
	public String getCrc() {
		return mainPanel.getCrc();
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see mv.releaser.view.InterfaceMainWindow#getDate()
	 */
	public Calendar getDate() {
		return mainPanel.getDate();
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see mv.releaser.view.InterfaceMainWindow#getGenre()
	 */
	public String getGenre() {
		return mainPanel.getGenre();
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see mv.releaser.view.InterfaceMainWindow#getFps()
	 */
	public String getFps() {
		return mainPanel.getFps();
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see mv.releaser.view.InterfaceMainWindow#getMinutes()
	 */
	public String getMinutes() {
		return mainPanel.getMinutes();
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see mv.releaser.view.InterfaceMainWindow#getSeconds()
	 */
	public String getSeconds() {
		return mainPanel.getSeconds();
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see mv.releaser.view.InterfaceMainWindow#getWidthResolution()
	 */
	public String getWidthResolution() {
		return mainPanel.getWidthResolution();
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see mv.releaser.view.InterfaceMainWindow#getHeightResolution()
	 */
	public String getHeightResolution() {
		return mainPanel.getHeightResolution();
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see mv.releaser.view.InterfaceMainWindow#getYear()
	 */
	public String getYear() {
		return mainPanel.getYear();
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see mv.releaser.view.InterfaceMainWindow#getType()
	 */
	public String getType() {
		return mainPanel.getType();
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see mv.releaser.view.InterfaceMainWindow#getAudio()
	 */
	public String getAudio() {
		return mainPanel.getAudio();
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see mv.releaser.view.InterfaceMainWindow#getSource()
	 */
	public String getSource() {
		return mainPanel.getSource();
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see mv.releaser.view.InterfaceMainWindow#getLanguage()
	 */
	public String getLanguage() {
		return mainPanel.getLanguage();
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see mv.releaser.view.InterfaceMainWindow#getDeinterlace()
	 */
	public String getDeinterlace() {
		return mainPanel.getDeinterlace();
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see mv.releaser.view.InterfaceMainWindow#getFormat()
	 */
	public String getFormat() {
		return mainPanel.getFormat();
	}

	public void updateLookAndFeelMenu(JMenu lookfeelMenu) {
		ButtonGroup bg = new ButtonGroup();
		Map<String, String> map = getLookAndFeelsMap();
		for (String clef : map.keySet()) {
			final String classe = map.get(clef);
			boolean natif = classe.equals(UIManager.getLookAndFeel().getClass()
					.getName());
			JRadioButtonMenuItem item = new JRadioButtonMenuItem(clef, natif);
			item.addActionListener(new ActionListener() {
				public void actionPerformed(ActionEvent ae) {
					try {
						UIManager.setLookAndFeel(classe);
					} catch (Exception e) {
						e.printStackTrace();
					}
					SwingUtilities.updateComponentTreeUI(MainWindowJFormD.this);
					pack();
				}
			});
			bg.add(item);
			lookfeelMenu.add(item);
		}
	}

	public String getRipper() {
		return mainPanel.getRipper();
	}

	public String getGroup() {
		return mainPanel.getGroup();
	}

	public DefaultComboBoxModel getGenreModel() {
		return mainPanel.getGenreModel();
	}

	public DefaultComboBoxModel getTypeModel() {
		return mainPanel.getTypeModel();
	}

	public DefaultComboBoxModel getAudioModel() {
		return mainPanel.getAudioModel();
	}

	public DefaultComboBoxModel getSourceModel() {
		return mainPanel.getSourceModel();
	}

	public DefaultComboBoxModel getLanguageModel() {
		return mainPanel.getLanguageModel();
	}

	public DefaultComboBoxModel getDeinterlaceModel() {
		return mainPanel.getDeinterlaceModel();
	}

	public DefaultComboBoxModel getFormatModel() {
		return mainPanel.getFormatModel();
	}

	public DefaultComboBoxModel getRipperModel() {
		return mainPanel.getRipperModel();
	}

	public DefaultComboBoxModel getGroupModel() {
		return mainPanel.getGroupModel();
	}

	public void setGenreModel(DefaultComboBoxModel model) {
		mainPanel.setGenreModel(model);
	}

	public void setTypeModel(DefaultComboBoxModel model) {
		mainPanel.setTypeModel(model);
	}

	public void setAudioModel(DefaultComboBoxModel model) {
		mainPanel.setAudioModel(model);
	}

	public void setSourceModel(DefaultComboBoxModel model) {
		mainPanel.setSourceModel(model);
	}

	public void setLanguageModel(DefaultComboBoxModel model) {
		mainPanel.setLanguageModel(model);
	}

	public void setDeinterlaceModel(DefaultComboBoxModel model) {
		mainPanel.setDeinterlaceModel(model);
	}

	public void setFormatModel(DefaultComboBoxModel model) {
		mainPanel.setFormatModel(model);
	}

	public void setRipperModel(DefaultComboBoxModel model) {
		mainPanel.setRipperModel(model);
	}

	public void setGroupModel(DefaultComboBoxModel model) {
		mainPanel.setGroupModel(model);
	}

	public boolean isHdtv() {
		return mainPanel.isHdtv();
	}

	public boolean isDvdrip() {
		return mainPanel.isDvdrip();
	}

	public boolean isProper() {
		return mainPanel.isProper();
	}

	public boolean isRepack() {
		return mainPanel.isRepack();
	}

	public boolean isReadNfo() {
		return mainPanel.isReadNfo();
	}

	public boolean isDirFix() {
		return mainPanel.isDirFix();
	}

	public boolean isNfoFix() {
		return mainPanel.isNfoFix();
	}

}
